//
//  HMVisitorViewController.swift
//  MyWeibo
//
//  Created by apple on 16/4/17.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit
//遵守代理协议
class HMVisitorViewController: UITableViewController,HMVisitorViewDelegate {

    //创建一个判断标示  更改判断标示
    var userLogon : Bool = HMUserAccountViewModel.sharedViewModel.login
    
    override func viewDidLoad() {
        
        userLogon ?super.loadView() : setupVisitorView()
    }

    
    //创建一个私有方法来加载到响应的控制器
    private func setupVisitorView(){
        
        view = VisitorView
        
        //加载控制器的时候创建item  添加左右的按键
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "didClickregisterButton")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "didClickLonginButton")
        
    }
    
    //代理方法的实现
    func didClickLonginButton() {
        
        print("点击登录")
        
        //登录的时候mota出一个控制器
        let loginVc:HMLonginController = HMLonginController()
        //包装成导航控制器
        presentViewController(UINavigationController(rootViewController: loginVc), animated: true, completion: nil)
        

    }
    
    func didClickregisterButton() {
        print("点击注册方法")
    }
    
    
    //懒加载view
//    lazy var VisitorView:HMVisitorView = HMVisitorView()
    
    //懒加载view
    lazy var VisitorView:HMVisitorView = {
        
        let view = HMVisitorView()
        //设置代理
        view.delegate = self
        return view
    }()
    
}
